package com.olah.common.entity.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.olah.common.entity.enums.HttpStatus;

/**
 * 通用返回值
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UtilResponse<T> {

    // 状态码
    private int status;

    // 附加消息
    private String msg;

    // 响应内容
    private T data;

    public UtilResponse(HttpStatus status, String msg) {
        this.status = status.getStatus();
        this.msg = msg;
    }

    public UtilResponse(HttpStatus status, T data) {
        this.status = status.getStatus();
        this.data = data;
    }

    public UtilResponse(HttpStatus status, String msg, T data) {
        this.status = status.getStatus();
        this.msg = msg;
        this.data = data;
    }

    public static <T> UtilResponse<T> success(T data) {
        return new UtilResponse<>(HttpStatus.SUCCESS, data);
    }

    public static <T> UtilResponse<T> success(String msg, T data) {
        return new UtilResponse<>(HttpStatus.SUCCESS, msg, data);
    }

    public static <T> UtilResponse<T> error(String msg) {
        return new UtilResponse<>(HttpStatus.FAILED, msg);
    }

    public static <T> UtilResponse<T> success(String msg) {
        return new UtilResponse<>(HttpStatus.SUCCESS, msg, null);
    }
}
